package com.moli.iov.open.service.impl;

import com.moli.iov.base.enums.ParamUnitEnum;
import com.moli.iov.base.enums.SysParamSettingEnum;
import com.moli.iov.base.model.dto.req.SysParamSettingsReqDto;
import com.moli.iov.base.model.dto.res.SysParamSettingsResDto;
import com.moli.iov.base.remote.ISysParamSettingsRemoteService;
import com.moli.iov.base.util.CollectionUtils;
import com.moli.iov.open.service.SysParamSettingsService;
import com.moli.iov.rest.RestResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * The type Sys param settings service.
 *
 * @author whl
 */
@Service
public class SysParamSettingsServiceImpl implements SysParamSettingsService {
    @Reference(group = "${service.group}", check = false)
    private ISysParamSettingsRemoteService settingsRemoteService;

    @Override
    public RestResponse getSysParamSettings(Long companyId) {
        RestResponse<List<SysParamSettingsResDto>> list = settingsRemoteService.listSysParamSettingsOp(companyId);
        if (!RestResponse.isSuccess(list)) {
            return RestResponse.success();
        }
        for (SysParamSettingsResDto datum : list.getData()) {
            if (Objects.equals(datum.getParamCode(), SysParamSettingEnum.OFFLINE_ALARM_DURATION.getDictCode())) {
                return RestResponse.success(datum);
            }
        }
        return RestResponse.success();
    }

    @Override
    public RestResponse updateSysParamSettings(SysParamSettingsReqDto dto) {
        return settingsRemoteService.updateSysParamSettings(dto);
    }
}
